package org.xukai.common.util.json;

import com.alibaba.fastjson.JSON;
import java.util.ArrayList;
import java.util.List;

/**
 * JSON数据版本的构造器数据
 * @author JackyLIU
 *
 */
public class MenuConfBuilder {

	public static int masterLoc = 1;
	
	public static int tradeLoc = 1;
	
	public static int itemLoc = 1;
	
	public static void main(String[] args) {
		MenuConf conf = new MenuConf();
		conf.setMenuInfos(new ArrayList<MenuInfo>());
		List<MenuInfo> l = conf.getMenuInfos();
		long index = 1;
		l.add(buildMaster(index++, "icon-home", "首页", "/index/", null));
		MenuInfo trade = buildTrade(index++, "icon-order", "交易管理", null, null);
		buildTrade(index++, "trade_list_nav", "订单处理", "/trade/list/?queryId=1&sys=true", trade);
		buildTrade(index++, "pt_list_nav", "快递单模板", "/pt/list/", trade);
		buildTrade(index++, "pt_deliver_list_nav", "发货单模板", "/pt/deliver_list/", trade);
		buildTrade(index++, "pt_custom_nav", "自定义打印", "/pt/custom/?queryId=1&sys=true", trade);
		buildTrade(index++, "pt_product_short_nav", "商品简称", "/pt/product_short/", trade);
		buildTrade(index++, "pt_print_log_nav", "打单发货日志", "/pt/print_log/", trade);
		buildTrade(index++, "pt_smart_match_nav", "快递智能匹配", "/pt/smart_match/", trade);
		l.add(trade);
		
		/*MenuInfo item = buildItem(index++, "icon-product", "商品管理", null, null);
		buildItem(index++, "prod_prod_info_nav", "单品规格", "/prod/prod_info/", item);
		buildItem(index++, "prod_cata_management_nav", "分类管理", "/prod/cata_management/", item);
		buildItem(index++, "prod_prod_statistic_nav", "商品销量统计", "/prod/prod_statistic/", item);
		l.add(item);
		
		MenuInfo stock = buildItem(index++, "icon-stock", "库存管理", null, null);
		buildItem(index++, "st_stock_list", "库存管理", "/stock/list/", stock);
		buildItem(index++, "st_add_list", "入库统计", "/stock/stock_log_add/", stock);
		buildItem(index++, "st_educe_list", "出库统计", "/stock/stock_log_reduce/", stock);
		l.add(stock);*/
		
		MenuInfo sms = buildTrade(index++, "icon-message", "短信服务", null, null);
		buildTrade(index++, "sms_settings_nav", "短信服务设置", "/sms/settings/", sms);
		buildTrade(index++, "sms_sent_log_nav", "短信发送记录", "/sms/sent_log/", sms);
		buildTrade(index++, "sms_txn_log_nav", "短信充值记录", "/sms/txn_log/", sms);
		l.add(sms);
		
		MenuInfo sysConf = buildMaster(index++, "icon-system", "系统设置", null, null);
		buildMaster(index++, "setting_shop_info_nav", "店铺信息设置", "/setting/shop_info/", sysConf);
		buildMaster(index++, "setting_sync_option_nav", "同步设置", "/setting/sync_option/", sysConf);
		l.add(sysConf);
		
		System.out.println(JSON.toJSONString(conf.getMenuInfos()));
	}
	
	static MenuInfo build(Long id, String icon, String kind, int loc, String name, String domain, String userLevel, String path, MenuInfo parent){
		MenuInfo info = new MenuInfo();
		info.setId(id);
		info.setIcon(icon);
		info.setKind(kind);
		info.setLoc(loc+"");
		info.setName(name);
		info.setDomain(domain);
		info.setUserLevel(userLevel);
		info.setPath(path);
		if(null != parent){
			info.setParentId(parent.getId());
			if(null == parent.getChildren())
				parent.setChildren(new ArrayList<MenuInfo>());
			parent.getChildren().add(info);
		}
		return info;
	}
	
	/**
	 * 构建erp.superboss.cc域名下的菜单
	 * @param id
	 * @param kind
	 * @param loc
	 * @param name
	 * @param path
	 * @param parent
	 * @return
	 */
	static MenuInfo buildMaster(Long id, String icon, String name, String path, MenuInfo parent){
		return build(id, icon, "1", masterLoc++, name, "jxc.superboss.cc", "1", path, parent);
	}
	
	static MenuInfo buildTrade(Long id, String icon, String name, String path, MenuInfo parent){
		return build(id, icon, "2", tradeLoc++, name, "trade.jxc.superboss.cc", "1", path, parent);
	}
	
	/**
	 * 构建item.erp.superboss.cc域名下的菜单
	 * @param id
	 * @param kind
	 * @param loc
	 * @param name
	 * @param path
	 * @param parent
	 * @return
	 */
	static MenuInfo buildItem(Long id, String icon, String name, String path, MenuInfo parent){
		return build(id, icon, "3", itemLoc++, name, "item.jxc.superboss.cc", "1", path, parent);
	}

}
